//public class MyException extends Exception {}
/**
    Using List for Stack implementation
    LIFO Stack implementation
*/
global class Assignment5StackClass {
    
    List<String> elemList;
    public class EmptyStackException extends Exception {}
    
    Assignment5StackClass(){
         elemList = new List<String>();
    }
    
    public String push(String elem){
        Integer len = size();
        //elemList.set(len, elem);
        elemList.add(elem);
        return elem;
    }
    
    
    public String pop() {
       Integer len = size();
       if(len == 0)
           throw new EmptyStackException() ;
      
       String obj = peek();
       elemList.remove(len - 1);
       return obj;

    }
    
    
    public String peek() {
        Integer len = size();
        if(len == 0)
           throw new EmptyStackException() ;     
        return elemList.get(len - 1);

    }
    
    public Integer size(){
        Integer len = 0;
        for( String elem: elemList) {
            len++;
        }
        return len;
    }
    
    public static testMethod void testStack() {
        Assignment5StackClass testStack = new Assignment5StackClass();
        testStack.push('1');
        testStack.push('2');
        testStack.push('3');
        
        System.assertEquals('3' , testStack.pop() );
        
        //System.assertEquals(3, testStack.size());
    }
    
}